<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>更新时刻表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <script src="js/jquery-3.6.0.min.js"></script>

    <script>
        /* 初始化 */
        function init() {
            var data = JSON.parse(window.sessionStorage.getItem('timetable') || []);
            $("input[name='timetableId']").attr("value", data.timetableId)
            $("input[name='timetableTrain']").attr("value", data.timetableTrain)
            $("input[name='timetableStartStation']").attr("value", data.timetableStartStation)
            $("input[name='timetableEndStation']").attr("value", data.timetableEndStation)
            $("input[name='timetableDeparture']").attr("value", data.timetableDeparture)
            $("input[name='timetableArrive']").attr("value", data.timetableArrive)
            $("input[name='timetableSeat']").attr("value", data.timetableSeat)
            /* 清理session */
            window.sessionStorage.removeItem('timetable');
        }

        /* Ajax异步更新用户信息 */
        function update(data) {
            //请求参数
            var admin = data.field;
            $.ajax({
                //请求方式
                type: 'POST',
                //请求的媒体类型
                contentType: 'application/json;charset=UTF-8',
                //请求地址
                url: 'rbsystemTimetable/update',
                //数据，json字符串
                data: JSON.stringify(admin),
                // 请求数据类型
                dataType: 'JSON',
                //请求成功
                success: function (data) {
                    // 经过了fastjson自动转成了对象
                    if (data.code === 0) {
                        /* 调用顶层窗口的跳转方法 父窗口：window.parent */
                        window.top.location.href = 'javascript:history.go(-1)';
                        window.top.alert("更新成功！");
                    } else {
                        layer.alert('修改失败！');
                    }
                },
                error: function () {
                    layer.alert("修改失败！");
                }
            });
        }

        function goBack() {
            window.top.location.href = 'javascript:history.go(-1)';
        }
    </script>

    <script src="layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script>
        layui.use(['layer', 'form', 'laydate'], function () {
            var form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate
            init();

            //监听提交
            form.on('submit(demo1)', function (data) {
                update(data);
            });

            //同时绑定多个
            lay('.test-item').each(function () {
                laydate.render({
                    elem: this
                    , type: 'datetime'
                });
            });

        });
    </script>
</head>

<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>更新时刻表</legend>
</fieldset>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input type="text" name="timetableId" disabled="true" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">车次号</label>
        <div class="layui-input-block">
            <input type="text" name="timetableTrain" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">出发站</label>
        <div class="layui-input-block">
            <input type="text" name="timetableStartStation" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">到达站</label>
        <div class="layui-input-block">
            <input type="text" name="timetableEndStation" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">发车时间</label>
        <div class="layui-input-block">
            <input type="text" name="timetableDeparture" autocomplete="off" class="layui-input  test-item"
                   placeholder="请选择发车时间 格式：yyyy-MM-dd HH:mm:ss">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">到站时间</label>
        <div class="layui-input-block">
            <input type="text" name="timetableArrive" autocomplete="off" class="layui-input  test-item"
                   placeholder="请选择到站时间 格式：yyyy-MM-dd HH:mm:ss">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商务座</label>
        <div class="layui-input-block">
            <input type="text" name="timetableSeat" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1" onclick="return false">立即提交</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="goBack()">返回</button>
        </div>
    </div>
</form>
</body>
</html>
